package leecode

func maximumSumOfHeights(maxHeights []int) int64 {
	var result int
	for i := 0; i < len(maxHeights); i++ {
		//当前节点的左边递减
		temp := maxHeights[i]
		tempSum := temp
		//如果当前节点作为最大值 从右向左递减
		for left := i - 1; left >= 0; left-- {
			temp = min(temp, maxHeights[left])
			tempSum += temp
		}

		temp = maxHeights[i] //当前节点的右边递减
		for right := i + 1; right < len(maxHeights); right++ {
			temp = min(temp, maxHeights[right])
			tempSum += temp
		}
		if tempSum > result {
			result = tempSum
		}
	}
	return int64(result)
}
